package com.test19_多线程;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * Callable接口，有返回值
 */
public class Demo04_Callable {

    public static void main(String[] args) throws Exception {
        MyThread4 myThread = new MyThread4();   // 创建Callable接口对象
        FutureTask<String> future = new FutureTask<>(myThread);     // 包装了Callable接口对象
        Thread thread = new Thread(future);
        thread.start();     // 启动多线程
        try {
            System.out.print(future.get());     // 异步获取
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class MyThread4 implements Callable<String> {
    @Override
    public String call() throws Exception {
        String result = "";
        for (int x = 0; x < 10; x++) {
            result += String.format("【%d】沐言科技：www.yootk.com%n", x);
        }
        return result;
    }
}
